import Vue from 'vue'
import Vuex from 'vuex'
import {LoginApi} from '../request/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    menu: [
      // { id: 3, user_id: 2, path: "/category", path_name: "分类页面" },
      // { id: 4, user_id: 2, path: "/good", path_name: "商品页面" },
      // { id: 6, user_id: 2, path: "/order", path_name: "订单页面" }
    ]
  },
  mutations: {
    // 存token值
    SaveToken(state,payload){
      state.token=payload
    },
    // 存菜单值
    SaveMenu(state,payload){
      state.meue=payload
    }
  },
  actions: {
    // 登录的方法
    login({state,commit},payload){
      return new Promise((resolve,reject)=>{
        LoginApi(payload).then(res=>{
          resolve(res)
          if(res.errno===0){
           commit('SaveToken',res.data.token)
          //  state.token=payload
           localStorage.setItem('token',res.data.token)
          }
        })
      })
     
    }
  },
  modules: {
  }
})
